package com.hfy.user.controller;

import com.hfy.model.dto.user.OpenSessionDto;
import com.hfy.user.service.SessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

/**
 * @ author 韩
 * time: 2024/11/4 9:51
 */

@RestController
@RequestMapping("/session")
@Tag(name = "会话操作的控制器" ,description = "对会话进行一些管理操作")
public class SessionController {

    @Autowired
    private SessionService sessionService;

    @PostMapping("/open")
    @Operation(summary = "新打开一个会话", description = "当有了就不操作（逻辑删除业务）")
    @Parameters({@Parameter(name = "otherAccount", description = "私信的人的账号"),
            @Parameter(name = "myAccount", description = "我的账号")})
    public Result open(@RequestBody OpenSessionDto dto) {
        return sessionService.open(dto);
    }


    @GetMapping("/list/{account}")
    @Operation(summary = "获取会话列表", description = "根据聊天时间来加载会话列表")
    @Parameters({@Parameter(name = "account", description = "账号")})
    public Result getSessionList(@PathVariable("account") String account) {
        return sessionService.getSessionList(account);
    }


    @DeleteMapping("/remove/{account}/{toAccount}")
    @Operation(summary = "逻辑删除会话")
    @Parameters({@Parameter(name = "account", description = "会话所属账号"),
            @Parameter(name = "toAccount", description = "对话的账号账号")})
    public Result removeSession(@PathVariable("account") String account, @PathVariable("toAccount") String toAccount) {
        return sessionService.removeSession(account, toAccount);
    }


}
